home *** CD-ROM | disk | FTP | other *** search
Oberon Text | 1990-12-13 | 6.3 KB | 130 lines | [.Ob./.Ob2] |
- Syntax10.Scn.Fnt
- Syntax10i.Scn.Fnt
- Syntax10b.Scn.Fnt
- MODULE TestElems; (** CAS 15-Oct-90 **)
- IMPORT
- Oberon, Input, Display, Viewers, Files, Fonts, Printer, Texts,
- WriteTexts, WriteFrames, WriteParcs;
- CONST
- mm = WriteTexts.mm;
- rightKey = 0; middleKey = 1; leftKey = 2;
- TYPE
- TestElem = POINTER TO TestElemDesc;
- TestElemDesc = RECORD(WriteTexts.ElemDesc)
- data: ARRAY 8 OF CHAR
- END;
- NotifyMsg = RECORD(WriteFrames.NotifyMsg) END;
- PROCEDURE WriteString(VAR r: Files.Rider; s: ARRAY OF CHAR);
- VAR i: INTEGER;
- BEGIN i := 0;
- WHILE s[i] # 0X DO INC(i) END;
- Files.WriteBytes(r, s, i + 1)
- END WriteString;
- PROCEDURE ReadString(VAR r: Files.Rider; VAR s: ARRAY OF CHAR);
- VAR i: INTEGER; ch: CHAR;
- BEGIN i := 0;
- REPEAT Files.Read(r, ch); s[i] := ch; INC(i) UNTIL (ch = 0X) OR (i = LEN(s));
- IF ch # 0X THEN s[0] := 0X END
- END ReadString;
- PROCEDURE* TestHandle(E: WriteTexts.Elem; VAR msg: Display.FrameMsg);
- VAR e: TestElem; P: WriteTexts.Parc; x, y, w, h: INTEGER; keys, keysum: SET; visible: BOOLEAN;
- fnt: Fonts.Font; col: SHORTINT; X0, Y0: INTEGER;
- BEGIN
- WITH E: TestElem DO
- IF msg IS WriteFrames.PrepareMsg THEN (*element is about to be drawn or printed*)
- WITH msg: WriteFrames.PrepareMsg DO (*automatically adopt measures to element's environment*)
- P := WriteTexts.ParcBefore(WriteTexts.ElemBase(E), WriteTexts.ElemPos(E));
- E.H := P.lsp (*; E.W := P.width - msg.indent would adapt to remaining space in line*)
- END
- ELSIF msg IS WriteTexts.DrawMsg THEN (*element is fully visible: draw it to the screen*)
- WITH msg: WriteTexts.DrawMsg DO
- Display.ReplConst(15, msg.X0, msg.Y0, SHORT(E.W DIV msg.unit), SHORT(E.H DIV msg.unit),
- Display.replace)
- END
- ELSIF msg IS WriteTexts.PrintMsg THEN (*element is fully visible: print it*)
- WITH msg: WriteTexts.PrintMsg DO
- Printer.Line(msg.X0, msg.Y0, SHORT(E.W DIV msg.unit), SHORT(E.H DIV msg.unit))
- END
- ELSIF msg IS NotifyMsg THEN (*special viewer broadcast message*)
- WITH msg: NotifyMsg DO
- WriteFrames.LocateElem(msg.frame, E, visible, fnt, col, X0, Y0); (*check if indeed visible, i.e. not clipped*)
- IF visible THEN (*if so: update the single view in this frame*)
- Display.ReplConst(15, X0 + 1, Y0 + 1, SHORT(E.W DIV msg.unit) - 2, SHORT(E.H DIV msg.unit) - 2,
- Display.invert)
- END
- END
- ELSIF msg IS WriteTexts.LoadMsg THEN (*load element specific data*)
- WITH msg: WriteTexts.LoadMsg DO
- ReadString(msg.r, E.data)
- END
- ELSIF msg IS WriteTexts.StoreMsg THEN (*store element specific data*)
- WITH msg: WriteTexts.StoreMsg DO
- WriteString(msg.r, "TestElems.Alloc"); (*always write out the name of the allocation procedure first*)
- WriteString(msg.r, E.data)
- END
- ELSIF msg IS WriteTexts.CopyMsg THEN (*copy element*)
- WITH msg: WriteTexts.CopyMsg DO
- IF msg.e = NIL THEN NEW(e); msg.e := e ELSE e := msg.e(TestElem) END; (*if not yet allocated: do so*)
- e.data := E.data (*copy state into new element*)
- END
- ELSIF msg IS WriteFrames.TrackMsg THEN (*a mouse click hit the element*)
- WITH msg: WriteFrames.TrackMsg DO
- IF msg.keys = {middleKey} THEN keysum := msg.keys;
- w := SHORT(E.W DIV msg.unit); h := SHORT(E.H DIV msg.unit);
- Oberon.RemoveMarks(msg.X0, msg.Y0, w, h);
- Display.ReplConst(15, msg.X0 + 1, msg.Y0 + 1, w - 2, h - 2, Display.invert);
- REPEAT Input.Mouse(keys, msg.X, msg.Y); keysum := keysum + keys;
- Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, msg.X, msg.Y)
- UNTIL keys = {};
- Display.ReplConst(15, msg.X0 + 1, msg.Y0 + 1, w - 2, h - 2, Display.invert);
- IF (keysum = {middleKey, leftKey}) & (E.W > 4 * mm) THEN DEC(E.W, 2 * mm); E.DX := E.W + 2 * mm;
- WriteTexts.ChangedElem(E)
- ELSIF msg.keys = {middleKey, rightKey} THEN INC(E.W, 2 * mm); E.DX := E.W + 2 * mm;
- WriteTexts.ChangedElem(E)
- END
- END
- END
- END
- END
- END TestHandle;
- PROCEDURE* MiscHandle(E: WriteTexts.Elem; VAR msg: Display.FrameMsg); (*subclass handler of TestHandle*)
- BEGIN
- WITH E: TestElem DO
- IF msg IS WriteTexts.StoreMsg THEN
- WITH msg: WriteTexts.StoreMsg DO (*write the name of a nonexistent procedure -> cannot be loaded again*)
- WriteString(msg.r, "TestElems.Unknown");
- WriteString(msg.r, E.data)
- END
- ELSE TestHandle(E, msg)
- END
- END
- END MiscHandle;
- PROCEDURE Alloc*; (*allocation procedure for class TestElem; allocates specific element and installs handler*)
- VAR e: TestElem;
- BEGIN NEW(e); e.handle := TestHandle; Oberon.Par(WriteTexts.AllocPar).e := e
- END Alloc;
- PROCEDURE InsertNew*; (** W H demonstrates behaviour of trivial floating element**)
- VAR S: Texts.Scanner; w: LONGINT;
- e: TestElem; T: WriteTexts.Text; copyover: Oberon.CopyOverMsg;
- BEGIN Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(S); w := S.i; Texts.Scan(S);
- NEW(e); WriteTexts.OpenElem(e, TestHandle, (w + 2)*mm, w*mm, S.i*mm); e.data := "testing";
- T := WriteFrames.Text("", WriteParcs.defParc); WriteTexts.AppendElem(T, e);
- copyover.text := T; copyover.beg := 0; copyover.end := T.len;
- Oberon.FocusViewer.handle(Oberon.FocusViewer, copyover)
- END InsertNew;
- PROCEDURE InsertMisc*; (** W H demonstrates handling of elements which cannot be loaded on opening**)
- VAR S: Texts.Scanner; w: LONGINT;
- e: TestElem; T: WriteTexts.Text; copyover: Oberon.CopyOverMsg;
- BEGIN Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(S); w := S.i; Texts.Scan(S);
- NEW(e); WriteTexts.OpenElem(e, MiscHandle, (w + 2)*mm, w*mm, S.i*mm); e.data := "testing";
- T := WriteFrames.Text("", WriteParcs.defParc); WriteTexts.AppendElem(T, e);
- copyover.text := T; copyover.beg := 0; copyover.end := T.len;
- Oberon.FocusViewer.handle(Oberon.FocusViewer, copyover)
- END InsertMisc;
- PROCEDURE Broadcast*; (**demonstrate effect of special viewer broadcast message**)
- VAR msg: NotifyMsg;
- BEGIN Viewers.Broadcast(msg)
- END Broadcast;
- END TestElems.
- WriteParcs.Alloc
-